﻿var mShareTitle = '';
var mShareContent = '';
var mImgUrl = '';
var mDetailUrl = '';
var mAppId = '';
var mreportfunc = null;
function initShare(title, content, imgUrl, detailUrl, appId, reportfunc)
{
    mShareTitle = title;
    mShareContent = content;
    mImgUrl = imgUrl;
    mDetailUrl = detailUrl;
    mAppId = appId;
    if (typeof (reportfunc) != 'undefined')
    {
        mreportfunc = reportfunc;
    }
}
function shareFriend() { 
    WeixinJSBridge.invoke('sendAppMessage', {
        "appid": mAppId,
        "img_url": mImgUrl,
        "img_width": "640",
        "img_height": "640",
        "link": mDetailUrl,
        "desc": mShareContent,
        "title": mShareTitle
    }, function (res)
    {
        if (mreportfunc != null)
        {
            mreportfunc(res.err_msg);
        }
        _report('send_msg', res.err_msg);
    })
}
function shareTimeline() {
    WeixinJSBridge.invoke('shareTimeline', {
        "img_url": mImgUrl,
        "img_width": "640",
        "img_height": "640",
        "link": mDetailUrl,
        "desc": mShareContent,
        "title": mShareContent
    }, function (res)
    {
        if (mreportfunc != null)
        {
            mreportfunc(res.err_msg);
        }
        _report('timeline', res.err_msg);
    });
}
function shareWeibo() {
    WeixinJSBridge.invoke('shareWeibo', {
        "content": mShareContent,
        "url": mDetailUrl,
    }, function (res)
    {
        if (mreportfunc != null)
        {
            mreportfunc(res.err_msg);
        }
        _report('weibo', res.err_msg);
    });
}
// 当微信内置浏览器完成内部初始化后会触发WeixinJSBridgeReady事件。
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {

    // 发送给好友
    WeixinJSBridge.on('menu:share:appmessage', function (argv) {
        shareFriend();
    });

    // 分享到朋友圈
    WeixinJSBridge.on('menu:share:timeline', function (argv) {
        shareTimeline();
    });

    // 分享到微博
    WeixinJSBridge.on('menu:share:weibo', function (argv) {
        shareWeibo();
    });
}, false);

//分享弹出层
function sharePopupShow(o) {
    $(o).show();
}
function sharePopupHide(o) {
    $(o).hide();
}